<html>
<head>
<link rel=stylesheet type="text/css" href="main.css" media="screen">
</head>
<body>
<div id="Title">
	<p><b> URL Domain Info</b></p>
</div>
<p>
<div id="Theme">
	<div id="display"></div>
</div>
</p>
</body>
<script type="text/javascript" src="js/Answer.js"></script>
<script type="text/javascript" src="js/AnswerIP.js"></script>
<script type="text/javascript" src="js/ArrayList.js"></script>
<script type="text/javascript" src="js/Integer.js"></script>
<script type="text/javascript" src="js/String.js"></script>
<script type="text/javascript" src="js/IPChoice.js"></script>
<script type="text/javascript" src="js/DNSLookup.js"></script>
<script type="text/javascript" src="js/Response.js"></script>
<script type="text/javascript" src="js/Response.js"></script>
<script type="text/javascript" src="js/HistoryLookup.js"></script>
<!--<script type="text/javascript" src="../../sample.js"></script>-->
<script>

var CenterServer = "http://140.113.87.227/DepenDNS/post.php";
// addMethod - By John Resig (MIT Licensed)
function addMethod(object , name, fn ){
	var old = object[ name ];
	object[ name ] = function(){
		if ( fn.length == arguments.length )
			return fn.apply( this, arguments );
		else if ( typeof old == 'function' )
			return old.apply( this, arguments );
	};
}

var index = 0;

function init(){
	var status = document.getElementById('display');
	status.innerHTML = '';
}

function display( text ){
	var id = 'phrase' + index++;
	var status = document.getElementById('display');
	status.innerHTML += '<span id="'+ id + '"></span><br>';
	//var bullet = '(' + ( index ) + ') ';
	document.getElementById(id).innerHTML = text ;

}

var port = chrome.extension.connect({name: "parse_url"});
port.postMessage({popup: "URL"});
port.onMessage.addListener( function(msg){
		domain = msg.BackGround;
		if (domain == null)
		exit(0);
		SendHTTPRequest(domain);
		});

function SendHTTPRequest( DomainUrl )
{
	var xmlHttp = new XMLHttpRequest();
	// The browser does not support xmlHttpRequest
	if ( !xmlHttp ){
		display("Server offline<br>");
		return false;
	}
	var params = "ASK_URL="+DomainUrl+"&User=kent&Passwd=123";
	xmlHttp.open( 'POST' , CenterServer , true );
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.onreadystatechange = function () {
		if (xmlHttp.readyState == 4){
			if (xmlHttp.status == 200){
				var URLInfo = xmlHttp.responseText.replace(/.*\n?.*\|/,'');
				display( URLInfo+"\n"+DomainUrl );
				var grade = xmlHttp.responseText.match(/Grade: (\w+)/);
			}
		}
	}
	xmlHttp.send(params);

}

function get_domain_from_url(url)
{
	return  url.match(/:\/\/(.[^/]+)/)[1];
}


// free memory 

</script>

</html>
